﻿@{
    ViewBag.Title = "BillProductForm";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}@using LeSoft.Application.Code;
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId", _ProductType = "";
    var Type = request('Type');
    $(function () {
        InitialPage();
        GetGrid();
        GetTree1();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
    }
    function GetTree1() {

        var item = {
            height: $(window).height() - 20,
            url: "../../ResourceManage/RS_Product/GetTypeTreeJson",
            onnodeclick: function (item) {
                _ProductType = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = {
            ProductType: _ProductType,
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val(),
        };
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_Product/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 110,
            autowidth: true,
            multiselect: true,
            colModel: [
                { label: "主键", name: "Id", indexL: "Id", hidden: true },
                { label: "所属类别", name: "Type", index: "Type", width: 300, align: "center", sortable: false },
                { label: "物品编号", name: "Code", index: "Code", width: 150, align: "center", sortable: false },
                { label: "物品名称", name: "Name", index: "Name", width: 250, align: "center", sortable: false },
                { label: "规格型号", name: "ModelNo", index: "ModelNo", width: 150, align: "center", sortable: false },
                { label: "品牌", name: "Brand", index: "Brand", width: 150, align: "center", sortable: false },
                {
                    label: "计量单位", name: "Unit", index: "Unit", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        debugger;
                        return top.clientdataItem.CalUnit[cellvalue] == null ? "" : top.clientdataItem.CalUnit[cellvalue];
                    }
                },
                { label: "最大库存", name: "MaxVolume", index: "MaxVolume", width: 150, align: "center", sortable: false, hidden: true },
                { label: "最低库存", name: "MinVolume", index: "MinVolume", width: 100, align: "center", sortable: false, hidden: true },
                { label: "所属预算科目", name: "BudgetItemId", index: "BudgetItemId", width: 200, align: "center", sortable: false, hidden: true },
                { label: "含税单价", name: "TaxUnitPrice", index: "TaxUnitPrice", width: 150, align: "center", sortable: false },
                { label: "税率", name: "Tax", index: "Tax", width: 100, align: "center", sortable: false },
                { label: "税后单价", name: "UnitPrice", index: "UnitPrice", width: 200, align: "center", sortable: false },
                {
                    label: "是否有效", name: "EnabledMark", index: "EnabledMark", width: 100, align: "center", hidden: true,
                    formatter: function (cellvalue) {
                        return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "描述", name: "Description", index: "Description", width: 200, align: "center", sortable: false }
            ],
            viewrecords: true,
            rowNum: 3000, 
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');

            },
            gridComplete: function () {
                var rowIds = $gridTable.jqGrid('getDataIDs'); 
                for (var k = 0; k < rowIds.length; k++) {
                    var curRowData = $gridTable.jqGrid('getRowData', rowIds[k]);
                    var curChk = $("#" + rowIds[k] + "").find(":checkbox");
                    curChk.attr('name', 'checkboxname');   //给每一个checkbox赋名字
                    curChk.attr('value', curRowData['MY_ID']);   //给checkbox赋值
                    curChk.attr('title', curRowData['NAME']);
                }
            },

        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                ProductType: _ProductType,
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()
            };
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_Product/GetPageList",
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
    }

    function AcceptClick(callback) {

        var Data = [];
        var $gridTable = $('#gridTable');
        var obj = $gridTable.jqGrid("getRowData");
        debugger;
        for (var i = 1; i <= obj.length; i++) {
            var Ischk = $("#jqg_gridTable_" + i).is(':checked');
            if (Ischk) { 
                Data.push(obj[i - 1]);
            }
        }
        if (Data.length <= 0) {
            top.dialogTop('至少选择一条有效数据', 'error');
            return false;
        }
        if (Data.length <= 0) {
            dialogMsg("未选择物品！", 0);
            return false;
        }
        callback(Data)
        //dialogMsg("操作成功！", 1);
        dialogClose();

    }

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style=" overflow-y: auto; ">
            <div id="itemTree1"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td style="padding-left: 2px;">
                                <div class="btn-group" id="queryCondition">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">筛选条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="gridPanel">
                <table id="gridTable"></table>
            </div>
        </div>
    </div>
</div>

